home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr09 / vstsrc.zip / RST.C < prev    next >
C/C++ Source or Header  |  1995-01-25  |  12KB  |  369 lines

  1. /*
  2.  * %W% %E% %U%  [EXTREL_1.2]
  3.  *
  4.  * VersaTrack orbit calculations are based on those that appear in Dr. Manfred
  5.  * Bester's sattrack program (the Unix(tm) versions 1 and 2).
  6.  *
  7.  * The data from which the maps where generated come from "xsat", an
  8.  * X-Windows program by David A. Curry (N9MSW).
  9.  *
  10.  * Site coordinates come from various sources, including a couple of
  11.  * World Almanacs, and also from both of the programs mentioned above.
  12.  *
  13.  * The following are authors' applicable copyright notices:
  14.  *
  15.  *                                                                               
  16.  * Copyright (c) 1992, 1993, 1994 Manfred Bester. All Rights Reserved.        
  17.  *                                                                           
  18.  * Permission to use, copy, modify, and distribute this software and its      
  19.  * documentation for educational, research and non-profit purposes, without   
  20.  * fee, and without a written agreement is hereby granted, provided that the  
  21.  * above copyright notice and the following three paragraphs appear in all    
  22.  * copies.                                                                    
  23.  *                                                                              
  24.  * Permission to incorporate this software into commercial products may be    
  25.  * obtained from the author, Dr. Manfred Bester, 1636 M. L. King Jr. Way,     
  26.  * Berkeley, CA 94709, USA.                                                   
  27.  *                                                                             
  28.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,  
  29.  * SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF    
  30.  * THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE AUTHOR HAS BEEN ADVISED   
  31.  * OF THE POSSIBILITY OF SUCH DAMAGE.                                         
  32.  *                                                                             
  33.  * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT       
  34.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A    
  35.  * PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"       
  36.  * BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT,  
  37.  * UPDATES, ENHANCEMENTS, OR MODIFICATIONS.                                   
  38.  *                                                                             
  39.  *                                                                             
  40.  * Copyright 1992 by David A. Curry                                            
  41.  *                                                                             
  42.  * Permission to use, copy, modify, distribute, and sell this software and its 
  43.  * documentation for any purpose is hereby granted without fee, provided that  
  44.  * the above copyright notice appear in all copies and that both that copyright
  45.  * notice and this permission notice appear in supporting documentation.  The  
  46.  * author makes no representations about the suitability of this software for  
  47.  * any purpose.  It is provided "as is" without express or implied warranty.   
  48.  *                                                                             
  49.  * David A. Curry, N9MSW                                                       
  50.  * Purdue University                                                           
  51.  * Engineering Computer Network                                                
  52.  * 1285 Electrical Engineering Building                                        
  53.  * West Lafayette, IN 47907                                                    
  54.  * davy@ecn.purdue.edu                                                         
  55.  *                                                                             
  56.  * VersaTrack Copyright (c) 1993, 1994 Siamack Navabpour. All Rights Reserved.
  57.  *
  58.  * Permission is hereby granted to copy, modify and distribute VersaTrack
  59.  * in whole, or in part, for educational, non-profit and non-commercial use
  60.  * only, free of charge or obligation, and without agreement, provided that
  61.  * all copyrights and restrictions noted herein are observed and followed, and
  62.  * additionally, that this and all other copyright notices listed herein
  63.  * appear unaltered in all copies and in all derived work.
  64.  *
  65.  * This notice shall not in any way void or supersede any of the other authors
  66.  * rights or privileges.
  67.  *
  68.  * VersaTrack IS PRESENTED FREE AND "AS IS", WITHOUT ANY WARRANTY OR SUPPORT.
  69.  * YOU USE IT AT YOUR OWN RISK. The author(s) shall not be liable for any
  70.  * direct, indirect, incidental, or consequential damage, loss of profits or
  71.  * other tangible or intangible losses or benefits, arising out of or related
  72.  * to its use. VersaTrack carries no warranty, explicit or implied, including
  73.  * but not limited to those of merchantablity and fitness for a particular
  74.  * purpose.
  75.  *
  76.  * Siamack Navabpour, 12342 Hunter's Chase Dr. Apt. 2114, Austin, TX 78729.
  77.  * sia@bga.com or sia@realtime.com.
  78.  */
  79.  
  80.  
  81. #include <windows.h>
  82. #include <stdio.h>
  83. #include <math.h>
  84. #include <sys/types.h>
  85.  
  86. #include "vstdefs.h"
  87. #include "constant.h"
  88. #include "vsttype.h"
  89. #include "vstextrn.h"
  90. #include "resource.h"
  91.  
  92. static char *direction[] = {
  93.     "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S",
  94.     "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"
  95. };
  96.  
  97. static char     *bufp;
  98.  
  99. struct itemtag {
  100.     int item_id;
  101.     int offset;
  102. };
  103.  
  104. static struct itemtag Items[] = {
  105.     IDC_RST_TITLE,    0,
  106.     IDC_RST_DATE,     80,
  107.     IDC_RST_RISE,     120,
  108.     IDC_RST_SET,      150,
  109.     IDC_RST_DURATION, 220,
  110.     IDC_RST_MAXELEV,  180,
  111.     IDC_RST_DIR,      200,
  112.     -1, -1
  113. };
  114.  
  115. static double   risetime, settime, maxelev, lasttime;
  116. static char     risedir[4], setdir[4];
  117. static select_t *selectp;
  118. static track_t  *trackp;
  119. static result_t *resultp;
  120.  
  121. static void
  122. getdir(dir, str)
  123. double dir;
  124. char *str;
  125. {
  126.     double f;
  127.     char **cp;
  128.     
  129.     str[0] = 0;
  130.     for (f = 0, cp = direction; f < 360.0; f += (360.0/16.0), cp++)
  131.         if (dir >= f && dir < (f + (360.0/16.0))) {
  132.             strcpy(str, *cp);
  133.             break;
  134.         }
  135. }
  136.  
  137. static void
  138. bcopy(src, dst, n)
  139. void *src, *dst;
  140. register int n;
  141. {
  142.     register char *s,*d;
  143.     s = (char *) src;
  144.     d = (char *) dst;
  145.     for (; n>0; n--)
  146.         *d++ = *s++;
  147. }
  148.  
  149. static void
  150. rst_free()
  151. {
  152.     if (selectp)
  153.         safeFree((void *) selectp);
  154.     if (resultp)
  155.         safeFree((void *) resultp);
  156.     if (trackp)
  157.         safeFree((void *) trackp);
  158.     if (bufp)
  159.         safeFree((void *) bufp);
  160.     selectp = NULL;
  161.     resultp = NULL;
  162.     trackp = NULL;
  163.     bufp = NULL;
  164. }
  165.  
  166. static double predStopTime;
  167.  
  168. static BOOL
  169. rst_next(sp, ttime)
  170. select_t *sp;
  171. double *ttime;
  172. {
  173.     double predTime, slowStepTime, fastStepTime;
  174.     BOOL prevVisible, done;
  175.     track_t *tp;
  176.     result_t *rp;
  177.  
  178.     tp = sp->sl_tp;
  179.     rp = sp->sl_rp;
  180.  
  181.     predTime = *ttime;
  182.  
  183.     if (predTime == -1.0)
  184.         predTime = utctime();
  185.  
  186.     slowStepTime = tp->steptime;    /* 1.0 / tp->epochmeanmotion / 2000.0; */
  187.     fastStepTime = slowStepTime * 10.0;
  188.  
  189.     prevVisible = done = FALSE;
  190.     maxelev = -400.0;
  191.     done = FALSE;
  192.  
  193.     do {
  194.         if (predict(modelflag, sp, predTime) == 0)
  195.             break;
  196.  
  197.         if (rp->r_elevation >= minElevation) {
  198.             if (!prevVisible) {
  199.                 prevVisible = TRUE;
  200.                 risetime = predTime;
  201.                 getdir(rp->r_azimuth, risedir);
  202.                 maxelev = rp->r_elevation;
  203.             }
  204.             if (rp->r_elevation > maxelev)
  205.                 maxelev = rp->r_elevation;
  206.         }
  207.         else {
  208.             if (prevVisible) {
  209.                 settime = predTime;
  210.                 getdir(rp->r_azimuth, setdir);
  211.                 done = TRUE;
  212.             }
  213.             prevVisible = FALSE;
  214.         }
  215.  
  216.         predTime += (rp->r_elevation < VLOWELEV) ? fastStepTime : tp->steptime;
  217.  
  218.     } while (!done);
  219.  
  220.     *ttime = predTime;
  221.  
  222.     dateOnlyStr(risetime, tp->sitep,  sp->flags, 1, bufp+80);
  223.     timeStr(risetime, tp->sitep,  sp->flags, 1, bufp+120);
  224.     timeStr(settime, tp->sitep, sp->flags, 1, bufp+150);
  225.     sprintf(bufp+180,"%-3.1lf", maxelev);
  226.     sprintf(bufp+200,"%s  >>  %s",risedir, setdir);
  227.     durStr(settime - risetime, bufp+220);
  228.  
  229.     return (predTime <= predStopTime ? TRUE : FALSE);
  230. }
  231.  
  232. static LRESULT CALLBACK
  233. RSTProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
  234. {
  235.     POINT *p;
  236.     select_t *sp;
  237.     struct itemtag *itp;
  238.  
  239.     switch (message) {
  240.     case WM_INITDIALOG:
  241.         p = DialogPos(Gwnd, hwnd);
  242.         SetWindowPos(hwnd, 0, (int)p->x, (int)p->y, 0, 0,
  243.             SWP_NOZORDER | SWP_NOSIZE | SWP_SHOWWINDOW);
  244.         break;
  245.  
  246.     case RST_UPDATE:
  247.         sp = (select_t *) wparam;
  248.         for (itp = Items; itp->offset >= 0; itp++)
  249.             SendDlgItemMessage(hwnd, itp->item_id, WM_SETTEXT, (WPARAM) 0,
  250.                 (LPARAM) (bufp+itp->offset) );
  251.         return TRUE;
  252.  
  253.     case WM_COMMAND:
  254.         if (LOWORD(wparam) == IDNEXT) {
  255.             sp = (select_t *) GetWindowLong(hwnd, DWL_USER);
  256.             ASSERT(sp);
  257.             if (rst_next(sp, &lasttime))
  258.                 PostMessage(hwnd, RST_UPDATE, (WPARAM) 0, (LPARAM) sp);
  259.             else
  260.                 usermsg("Next rise beyond specified duration.");
  261.         }
  262.         else if (LOWORD(wparam) == IDOK) {
  263.             rst_free();
  264.             rsthwnd = NULL;
  265.             DestroyWindow(hwnd);
  266.         }
  267.         return TRUE;
  268.         
  269.     case WM_CLOSE:
  270.         rst_free();
  271.         DestroyWindow(hwnd);
  272.         rsthwnd = NULL;
  273.         break;
  274.         
  275.     case WM_DESTROY:
  276.         rst_free();
  277.         rsthwnd = NULL;
  278.         break;
  279.  
  280.     case WM_CTLCOLORDLG:
  281.     case WM_CTLCOLORSTATIC:
  282.         ColorSet(wparam, CWHITE, 7);  /* was white and dark blue=5 */
  283.         return (BOOL) hDrawBrush[7];  /* dark cyan = 6 */
  284.  
  285.     case WM_CTLCOLOREDIT:
  286.         ColorSet(wparam, CBLACK, 8);   /* was white and light blue=12 */
  287.         return (BOOL) hDrawBrush[8];    /* light grey = 8 */
  288.  
  289.     default:
  290.         break;
  291.     }
  292.     return FALSE;
  293. }
  294.  
  295.  
  296. void
  297. rst(sp)
  298. select_t *sp;
  299. {
  300.     double predTime;
  301.     track_t *tp;
  302.     result_t *rp;
  303.  
  304.     if (rsthwnd || !sp)
  305.         return;
  306.  
  307.     WaitCursor();
  308.     if (!selectp)
  309.         selectp = (select_t *) safeAlloc(sizeof(select_t));
  310.  
  311.     if (!trackp)
  312.         trackp  = (track_t *)  safeAlloc(sizeof(track_t));
  313.  
  314.     if (!resultp)
  315.         resultp = (result_t *) safeAlloc(sizeof(result_t));
  316.  
  317.     bcopy(sp,        selectp, sizeof(select_t));
  318.     bcopy(sp->sl_tp, trackp,  sizeof(track_t));
  319.     bcopy(sp->sl_rp, resultp, sizeof(result_t));
  320.  
  321.     sp = selectp;
  322.     sp->sl_tp = trackp;
  323.     tp = trackp;
  324.     sp->sl_rp = resultp;
  325.     rp = resultp;
  326.  
  327.     if (!tp->sitep || !tp->satp) {
  328.         rst_free();
  329.         NormCursor();
  330.         return;
  331.     }
  332.  
  333.     predTime = (tp->starttime == -1.0 ) ? utctime() : tp->starttime;
  334.  
  335.     predict_init(modelflag, sp, predTime);
  336.  
  337.     if (tp->satp->s_flags & SF_GEOSTAT) {
  338.         NormCursor();
  339.         sprintf(tmpbuf,"%s is Geostationary. Please use real-time Display.",
  340.             tp->satp->s_name);
  341.         usermsg(tmpbuf);
  342.         rst_free();
  343.         return;
  344.     }
  345.  
  346.     if (!bufp)
  347.         bufp = (char *) safeAlloc(260);
  348.  
  349.     sprintf(bufp, "%s  From  %-.31s,  %-.39s", tp->satp->s_name, tp->sitep->c_name,
  350.         tp->sitep->c_locale);
  351.  
  352.     predStopTime = predTime + tp->duration;
  353.  
  354.     if (predStopTime < tp->stoptime)
  355.         predStopTime = tp->stoptime;
  356.  
  357.     lasttime = predTime;
  358.  
  359.     (void) rst_next(sp, &lasttime);
  360.  
  361.     rsthwnd = CreateDialog(hInst, MAKEINTRESOURCE(IDD_RST), Gwnd, RSTProc);
  362.  
  363.     SetWindowLong(rsthwnd, DWL_USER, (long) sp);
  364.  
  365.     PostMessage(rsthwnd, RST_UPDATE, (WPARAM) 0, (LPARAM) sp);
  366.     NormCursor();
  367. }
  368.  
  369.